package io.characterStream.bufferedRorW.test;

import java.io.*;
import java.util.ArrayList;

/*
将学生对象存入文件
读取文件，将学生信息读取到程序，封装为对象，存入集合,打印
 */
public class test2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("HDay08/D.txt"));
        ArrayList<Student> list = new ArrayList<>();
        String line;
        while((line=br.readLine())!=null){
            String[] arr = line.split("-");
            Student stu = new Student(arr[0], Integer.parseInt(arr[1]));
            list.add(stu);
        }
        br.close();
        for (Student student : list) {
            System.out.println(student);
        }
    }

    private static void writeInfo() throws IOException {
        Student s1 = new Student("张三",23);
        Student s2 = new Student("李四",20);
        Student s3 = new Student("周期",18);
        BufferedWriter bw = new BufferedWriter(new FileWriter("HDay09/D.txt"));
        bw.write(s1.getName()+"-"+s1.getAge());
        bw.newLine();
        bw.write(s2.getName()+"-"+s2.getAge());
        bw.newLine();
        bw.write(s3.getName()+"-"+s3.getAge());
        bw.newLine();
        bw.close();
    }
}
